package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Package;
import com.itheima.service.SetmealService;
import com.itheima.util.QiNiuUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {


    @Reference
    private SetmealService setmealService;


    /**
     * 获取套餐列表
     * @return
     */
    @GetMapping("/getSetmeal")
    public Result findAll(){
        List<Package> list = setmealService.findAll();
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,list);
    }


    /**
     * 通过id获取套餐
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result findById(Integer id){
        Package pkg = setmealService.findById(id);
        pkg.setImg(QiNiuUtil.DOMAIN+"/"+pkg.getImg());
        return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS,pkg);
    }

}
